package com.tqw.favorites.controller;

import com.tqw.auth.feign.AuthFegin;
import com.tqw.entity.JWTUtil;
import com.tqw.favorites.entity.Result;
import com.tqw.favorites.entity.StatusCode;
import com.tqw.favorites.pojo.Favorites;
import com.tqw.favorites.service.FavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Van
 */
@RestController
@RequestMapping("/favorites")
public class FavoritesController {

    @Autowired
    private FavoritesService favoritesService;

    @Autowired
    private AuthFegin authFegin;

    @PostMapping("/list")
    public Result favorites(@RequestHeader("Authorization") String token){
        Integer id = JWTUtil.getId(token);
        if (id==null)
            return new Result(false, StatusCode.ERROR,"用户错误");
        List<Favorites> favorites = favoritesService.selectFavorites(id);
        return new Result(true,StatusCode.OK,"查询成功",favorites);
    }
}
